//
//  MHReplyListCell.m
//  ManHua
//
//  Created by 江子安 on 15/10/27.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHReplyListCell.h"
#import <UIButton+WebCache.h>
#import <SDWebImageManager.h>
#import "UIImage+Addiction.h"

@implementation MHReplyListCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _photoBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_photoBtn setBackgroundImage:[UIImage imageNamed:@"iconfont-ren"] forState:UIControlStateNormal];
        _photoBtn.frame = CGRectMake(10, 10, 40, 40);
        [self.contentView addSubview:_photoBtn];
        
        _nickLabel = [[UILabel alloc]init];
        _nickLabel.frame = CGRectMake(60, 10, 25, 200);
        [self.contentView addSubview:_nickLabel];
        
        _TypeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 35, 200, 15)];
        _TypeNameLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_TypeNameLabel];
        
        _dataLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 110, 10, 100, 20)];
        _dataLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_dataLabel];
        
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 60, SCREEN_WIDTH - 80, 40)];
        _contentLabel.numberOfLines = 0;
        _contentLabel.backgroundColor = [UIColor greenColor];
        _contentLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_contentLabel];
        
    }
    return self;
}

+ (CGFloat)heightOfString:(NSString *)string
{
    NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName];
    CGRect bounds = [string boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 80, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    return bounds.size.height;
}

+ (CGFloat)heightOfCellWithModdel:(MHComicComentModel *)model
{
    if ([self heightOfString:model.CommentContent] > 40) {
        return 60 + [self heightOfString:model.CommentContent]+10;
        
    }
    else
    {
        return 100;
    }
}


// 加载数据
- (void)configureDataWithModel:(MHComicComentModel *)model
{
    if (model.UserPhotoURL.length >1) {
        SDWebImageManager *manager = [[SDWebImageManager alloc]init];
        [manager downloadImageWithURL:[NSURL URLWithString:model.UserPhotoURL] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
            [_photoBtn setBackgroundImage: [UIImage circleImageWithImage:image borderWidth:0 borderColor:[UIColor clearColor]] forState:UIControlStateNormal];
        }];
    }
    _nickLabel.text = model.UserNick;
    _TypeNameLabel.text = model.ClientTypeName;
    _dataLabel.text = model.CommentDate;
    _contentLabel.text = model.CommentContent;

    
    CGFloat height = [MHReplyListCell heightOfString:model.CommentContent];
    [self setFrameWithHeight:height];
    
}


// 重写frame
- (void)setFrameWithHeight:(CGFloat)height
{
    _contentLabel.frame = CGRectMake(60, 60, SCREEN_WIDTH - 80, height);
    
    
    
}










- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
